package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.android.http.HttpUtils;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecycleChildItemClickListener;
import com.lemon.smartsafety.utils.photo.GlideImageLoader;
import com.lemon.smartsafetynew.entity.highDanger.HighDangerItemVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/19.
 */

public class HighDangerAdapter extends LemonRcvAdapter<HighDangerItemVo> {

    private RecycleChildItemClickListener<HighDangerItemVo> mListener;

    public HighDangerAdapter(@Nullable List<HighDangerItemVo> data, RecycleChildItemClickListener<HighDangerItemVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<HighDangerItemVo> {

        private HighDangerItemVo data;
        private int pos;

        @Bind(R.id.record_item_iv)
        ImageView recordItemIv;
        @Bind(R.id.record_item_name_tv)
        TextView recordItemNameTv;
        @Bind(R.id.record_info_iv)
        ImageView recordInfoIv;
        @Bind(R.id.record_high_danger_iv)
        ImageView recordHighDangerIv;
        @Bind(R.id.record_high_danger_matter_tv)
        TextView recordHighDangerMatterTv;
        @Bind(R.id.record_high_danger_numbers_tv)
        TextView recordHighDangerNumbersTv;
        @Bind(R.id.record_high_danger_control_way_tv)
        TextView recordHighDangerControlWayTv;
        @Bind(R.id.record_high_danger_parameter_tv)
        TextView recordHighDangerParameterTv;
        @Bind(R.id.record_high_danger_monitor)
        ImageView recordHighDangerMonitor;
        @Bind(R.id.item_layout)
        RelativeLayout itemLayout;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_high_danger_info_recycler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {

            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });

            recordHighDangerMonitor.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onChildItemClick(data, pos);
                }
            });

        }

        @Override
        public void handleData(HighDangerItemVo highDangerItemVo, int position) {
            data = highDangerItemVo;
            pos = position;

            if(highDangerItemVo.getPicture() != null)
                GlideImageLoader.loadImage(recordHighDangerIv.getContext(), HttpUtils.formatFilesUrl(highDangerItemVo.getPicture().split(",")[0]), recordHighDangerIv, R.mipmap.high_danger);

            recordItemIv.setBackgroundResource(R.mipmap.icon_small_record_high_danger);
            recordItemNameTv.setText(CommonUtil.avoidNullString(highDangerItemVo.getName()));
            recordHighDangerMatterTv.setText(CommonUtil.avoidNullString(highDangerItemVo.getThing()));
            recordHighDangerNumbersTv.setText(CommonUtil.avoidNullString(highDangerItemVo.getNumber()));
            recordHighDangerControlWayTv.setText(CommonUtil.avoidNullString(highDangerItemVo.getControlModel()));
            recordHighDangerParameterTv.setText(CommonUtil.avoidNullString(highDangerItemVo.getMonitoredParameter()));
        }
    }
}
